package com.liuyucheng.idea_springboot.controller;

import com.liuyucheng.idea_springboot.bean.User;
import com.liuyucheng.idea_springboot.bean.UserThymeleaf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    @GetMapping({"/index","/"})
    public String index(Model model){
        model.addAttribute("item","五道口");

        User user = new User();
        user.setUsername("刘宇诚");

        model.addAttribute("user",user);
        return "/index";
    }

    @RequestMapping("/test")
//    @LogTrack(value = "index接口")
    public ModelAndView test(HttpServletRequest request){
        UserThymeleaf user = new UserThymeleaf();
        user.setLoginName("刘宇诚");
        user.setId(1);
        user.setBindType(1);

        ModelAndView mav = new ModelAndView();
        mav.addObject("user",user);
        mav.setViewName("/user/userInfo.html");
        return mav;
    }
}
